/**    
* @Description: 需要编辑正文的流程，统一用正文下载Action
* @author shuq techisone@gmail.com  
* @date 2012-4-28 上午08:54:03 
* @version V1.0   
*/ 


package net.sxnic.workflow.zw.action;

import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import net.sxnic.comm.utils.PropertyUtil;
import net.sxnic.workflow.WfActionSupport;
import net.sxnic.workflow.utils.WorkflowUtils;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

public class DownLoadDoc extends WfActionSupport{
	
	private static final long serialVersionUID = 1L;

	private File downFile;

	private String downloadFileName;

	public String execute() throws Exception {

		if (StringUtils.isBlank(id)) {
			return NOTAUTHORIZED;
		}
		//获取文档类型(doc,wps)
		String docType = PropertyUtil.getProperty("senddoc.operate.type");
		
		wfentity = wfenManager.get(id);
		
		String filePath = WorkflowUtils.getSendDocPath(id,wfentity.getCate1(), wfentity.getNigaoYear())+"-"+wfentity.getCate2()+"."+docType;

		downFile = new File(filePath);

		if (!downFile.isFile()) {
			return INPUT;
		}
		return SUCCESS;
	}


	/**
	 * 获取文件流
	 * 
	 * @return
	 * @throws Exception
	 */
	public InputStream getInputStream() throws Exception {
		return FileUtils.openInputStream(downFile);
	}

	/**
	 * 保存的时候要显示的文件名
	 * 
	 * @return
	 */
	public String getDownloadFileName() {
		String downFileName = downFile.getName();

		try {
			downloadFileName = new String(downFileName.getBytes(), "ISO8859-1");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		return downFileName;
	}

	public File getDownFile() {
		return downFile;
	}

	public void setDownFile(File downFile) {
		this.downFile = downFile;
	}


	public void setDownloadFileName(String downloadFileName) {
		this.downloadFileName = downloadFileName;
	}
}
